package com.net;

public class Ticket {
  public static void main(String[] args) {
//    new TicketWindow("中国银行bbc 1号柜台").start();
//    new TicketWindow("中国银行bbc 2号柜台").start();
//    new TicketWindow("中国银行bbc 3号柜台").start();

    final TicketWindowRunnable windowRunnable = new TicketWindowRunnable();
    new Thread(windowRunnable, "中国银行bbc 1号柜台").start();
    new Thread(windowRunnable, "中国银行bbc 2号柜台").start();
    new Thread(windowRunnable, "中国银行bbc 3号柜台").start();
  }
}

class TicketWindow extends Thread {
  private final String name;

  private static final int MAX = 50;

  private static int index = 1;

  public TicketWindow(String name) {
    this.name = name;

  }

  @Override
  public void run() {
    while (index <= MAX) {
      System.out.println("柜台:" + name + ", 当前的号码是:" + (index++));
    }
  }
}

class TicketWindowRunnable implements Runnable {

  private static final int MAX = 50;

  private int index = 1;

  @Override
  synchronized public void run() {
    while (index <= MAX) {
      System.out.println(Thread.currentThread().getName() + ", 当前的号码是:" + (index++));
      try {
        Thread.sleep(100);
      } catch (InterruptedException e) {
        e.printStackTrace();
      }
    }
  }
}

